// pages/gang/productManage/productManage.js
const app = getApp()
var util = require('../../../utils/util.js')
var http = require('../../../utils/server.js')

Page({
  data: {
    showDialog: false,
    putaway: ['自动上架', '手动上架'],
    mode: ['展示全部商品'],
    index: 0,
    zindex: 0
  },
  onLoad: function() {
    var that = this
    http.post({
      url: "product/getSettings",
    }, function(data) {
      that.setData({
        putaway: data.putaway,
        index: data.selected_putaway,
        mode: data.show_settings,
        zindex: data.select_show_settings,
      })
    })

  },
  tip: function() {
    var that = this
    that.setData({
      showDialog: true
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#7f7f7f',
    })
  },
  closeTip: function() {
    var that = this
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff',
    })
    that.setData({
      showDialog: false
    })
  },
  bindPickerChange: function(e) {
    this.setData({
      index: e.detail.value
    })
    this.saveData()
  },
  bindModeChange: function(e) {
    this.setData({
      zindex: e.detail.value
    })
    this.saveData()
  },
  saveData() {
    var that = this
    http.post({
      url: "product/setSettings",
      putaway: that.data.index,
      show_settings: that.data.zindex
    }, function(data) {
      util.showSuccess('设置成功')
    })
  }
})